﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace M3G {
    public class PolygonMode : Object3D {

        #region Constant
        // Culling mode
        public const int CullBack    = 160;
        public const int CullFront   = 161;
        public const int CullNone    = 162;
        // Shading mode
        public const int ShadeFlat   = 164;
        public const int ShadeSmooth = 165;
        // Winding mode
        public const int WindingCCW  = 168;
        public const int WindingCW   = 169;
        #endregion

        #region Field
        int   culling;
        int   winding;
        float lineWidth;
        bool  perspectiveCorrectionEnabled;
        #endregion

        #region Method
        public PolygonMode () {
            this.culling = CullBack;
            this.winding = WindingCCW;
            this.lineWidth = 1.0f;
            this.perspectiveCorrectionEnabled = true;
        }

        protected PolygonMode (PolygonMode polygonMode) : base(polygonMode) {
            this.culling = polygonMode.culling;
            this.winding = polygonMode.winding;
            this.lineWidth = polygonMode.lineWidth;
            this.perspectiveCorrectionEnabled = polygonMode.perspectiveCorrectionEnabled;
        }

        public int Culling {
            get { return culling; }
            set { 
                var culling = value;
                if (culling < CullBack || culling > CullNone) {
                    throw new ArgumentException ("Culling mode must be CullBack,CullFront,CullNone");
                }

                this.culling = culling;
            }

        }

        public int Winding {
            get { return winding; }
            set {
                var winding = value;
                if (winding != WindingCCW && winding != WindingCW) {
                    throw new ArgumentException ("Winding mode must be WindingCCW,WindingCW");
                }

                this.winding = winding;
            }
        }

        public float LineWidth {
            get { return lineWidth; }
            set {
                var lineWidth = value;
                if (lineWidth < 0) {
                    throw new ArgumentException ("LineWidh must be within [0,inf], width=" + lineWidth);
                }
                this.lineWidth = lineWidth;
            }
        }

     
        public bool PerspectiveCorrectionEnabled {
            get { return perspectiveCorrectionEnabled; }
            set { perspectiveCorrectionEnabled = value; }
        }

        public override Object3D Duplicate () {
            return new PolygonMode (this);
        }
        #endregion

    }
}
